<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="80px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-2">
  <div class="pagination-wrap-position table-wrap">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center">商户ID</th>
          <th nzAlign="center">商户名称</th>
          <th nzAlign="center">所属拓展员（ID）</th>
          <th nzAlign="center">状态</th>
          <th nzAlign="center">申请时间</th>
          <th nzAlign="center">操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 商户ID -->
          <td nzAlign="center">{{ data.id }}</td>
          <!-- 商户名称 -->
          <td nzAlign="center">{{ data.merchantName || '-' }}</td>
          <!-- 所属拓展员（ID） -->
          <td nzAlign="center">{{ data.userName }}（{{ data.userId }}）</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | unionPayMerchantStatus: 'color'}">
              {{ data.status | unionPayMerchantStatus: 'label' }}
            </span>
            <i
              *ngIf="data.status === 2"
              nz-icon
              nzType="exclamation-circle"
              nzTheme="outline"
              nz-tooltip
              [nzTooltipTitle]="data.auditOpinion"
            ></i>
          </td>
          <!-- 申请时间 -->
          <td nzAlign="center">{{ data.applicationTime || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center">
            <a
              nz-button
              nzType="link"
              nzSize="small"
              routerLink="/cooperation/cooperation-merchant-details"
              [queryParams]="{id: data.id}"
            >查看</a>

            <button
              *ngIf="data.status === 0"
              nz-button
              nzType="link"
              nzSize="small"
              (click)="showExamineModal(data)"
            >审核</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 审核 Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isExamineVisible"
  [nzTitle]="'审核'"
  (nzOnCancel)="isExamineVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-textarea-count [nzMaxCharacterCount]="150">
        <textarea
          rows="4"
          nz-input
          maxlength="150"
          placeholder="请输入审核意见"
          [(ngModel)]="auditOpinion"
        ></textarea>
      </nz-textarea-count>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="subExamine(1)">审核通过</button>
        <button nz-button nzType="primary" nzDanger (click)="subExamine(2)">审核不通过</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 审核 Modal -->